package com.yang.mall.exception;


public class GzSparkException extends RuntimeException {
    private static final long serialVersionUID = 5539431043384054654L;
    //系统异常消息码
    public static final String SYS_ERROR_MSGCD = BaseExceptionDefine.SYSTEM_BUSY_CODE+"";

    private String msgCd;
    private String msgInfo;
    private Throwable cause;
    //是否业务异常，业务代码中只能抛出业务异常
    private boolean businessException = false;

    /**
     * @param msgCd
     * @param msgInfo
     * @param cause
     */
    public GzSparkException(String msgCd, String msgInfo, Throwable cause) {
        super(msgInfo, cause);
        this.msgCd = msgCd;
        this.msgInfo = msgInfo;
        this.cause = cause;
    }

    /**
     * @param msgCd
     * @param msgInfo
     */
    public GzSparkException(String msgCd, String msgInfo) {
        super(msgInfo);
        this.msgCd = msgCd;
        this.msgInfo = msgInfo;
    }


    /**
     * @param msgCd
     */
    public GzSparkException(String msgCd) {
        super(msgCd);
        this.msgCd = msgCd;
    }

    public GzSparkException(String msgCd, boolean businessException) {
        super(msgCd);
        this.msgCd = msgCd;
        this.businessException = businessException;
    }

    /**
     * @param cause
     */
    public GzSparkException(Throwable cause) {
        super(SYS_ERROR_MSGCD, cause);
        this.cause = cause;
        this.msgCd = SYS_ERROR_MSGCD;
    }

    /**
     * @param msgInfo
     * @param cause
     */
    public GzSparkException(String msgInfo, Throwable cause) {
        super(msgInfo);
        this.msgCd = SYS_ERROR_MSGCD;
        this.msgInfo = msgInfo;
        this.cause = cause;
    }

    public GzSparkException() {
        super(SYS_ERROR_MSGCD);
        this.msgCd = SYS_ERROR_MSGCD;
    }

    public static void throwBusinessException(String msgCd) {
        throw new GzSparkException(msgCd, true);
    }

    public static void throwGzsparkException() {
        throw new GzSparkException();
    }

    /**
     * @param msgCd
     */
    public static void throwGzsparkException(String msgCd) {
        throw new GzSparkException(msgCd);
    }

    /**
     * @param t
     */
    public static void throwGzsparkException(Throwable t) {
        if(t instanceof GzSparkException) {
            throw (GzSparkException)t;
        }
        throw new GzSparkException(t);
    }

    /**
     * @param msgInfo
     * @param t
     */
    public static void throwGzsparkException(String msgInfo, Throwable t) {
        throw new GzSparkException(msgInfo, t);
    }

    /**
     * @param msgCd
     * @param msgInfo
     */
    public static void throwGzsparkException(String msgCd, String msgInfo) {
        throw new GzSparkException(msgCd, msgInfo);
    }

    /**
     * @param msgCd
     * @param msgInfo
     * @param throwable
     */
    public static void throwGzsparkException(String msgCd, String msgInfo, Throwable throwable) {
        throw new GzSparkException(msgCd, msgInfo, throwable);
    }


    public static GzSparkException create(String msgCd) {
        return new GzSparkException(msgCd);
    }

    public static GzSparkException create(String msgCd, String msgInfo) {
        return new GzSparkException(msgCd, msgInfo);
    }


    public String getMsgCd() {
        return msgCd;
    }

    public void setMsgCd(String msgCd) {
        this.msgCd = msgCd;
    }

    public String getMsgInfo() {
        return msgInfo;
    }

    public void setMsgInfo(String msgInfo) {
        this.msgInfo = msgInfo;
    }

    public Throwable getCause() {
        return cause;
    }

    public void setCause(Throwable cause) {
        this.cause = cause;
    }

    public boolean isBusinessException() {
        return businessException;
    }

    public void setBusinessException(boolean businessException) {
        this.businessException = businessException;
    }

}
